package com.moliku.insurance.common.util;


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;
import java.net.URL;

/**
 * @author 七分
 * @version 1.0
 * @date 2021/3/17 12:00
 * @effect
 */
public class WebServiceUtil {

//    public static String sendData(String url, String nameSpace, String methodName, String parameterName, byte[] data) {
    public static String sendData(String url, String nameSpace, String methodName, String parameterName, String data) {
        try {

            System.out.println("==============================调用start=======================================");
            Service service = new Service();
            Call call = new Call(service);
            call.setTargetEndpointAddress(new URL(url));
            //命名空间以及方法名
            call.setOperationName(new QName(nameSpace, methodName));
            //参数名//XSD_STRING:String类型//.IN入参
            call.addParameter(parameterName, XMLType.XSD_STRING, ParameterMode.IN);
            // 返回值类型：String
            call.setReturnType(XMLType.XSD_STRING);
            // 远程调用
            String result = (String) call.invoke(new Object[]{data});
            System.out.println("==============================调用end=======================================");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
